package cn.org.channl.server.action;

import cn.org.channl.message.Message;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;


/**
 * @author deacon
 * @since 2019/4/2
 */
@Slf4j
public class LoginAction extends ChannelActionAdapter {
    public LoginAction(ChannelHandlerContext channelHandlerContext, Message message) {
        super(channelHandlerContext, message);
    }

    @Override
    public void doExecute() {
        // 这里拼接报文 发送到 channel通道
        Object msg = "0x86";
        channelHandlerContext.writeAndFlush(msg).addListener(
                new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) {
                        if (future.isSuccess()) {
                            log.info("send success");
                            channelHandlerContext.channel().read();
                        } else {
                            future.channel().close();
                            log.info("send fail");
                        }
                    }
                });
    }
}
